<?php

class Guest extends CI_Controller{
	
	function __construct(){
		parent::__construct();
		$this->load->model('card');
	}

	function generate_cards(){
		$shuffled_cards = $this->card->shuffled_cards();// view all the cards

		shuffle($shuffled_cards);
	    $playercards = array();
	    $playerone = array();
	    $playertwo = array();
	    $trumpsuit = array();
	    $deck = array();
	    $tmp = array();

	    foreach($shuffled_cards as $row){
	    $playercards = array_slice($shuffled_cards, -12);
	    $playerone = array_slice($playercards, -6);

	    if (!in_array($row,$playercards)){
	    array_push($tmp,$row);
	    } 

	    } 

	    foreach ($playercards as $row) {

	    if(!in_array($row,$playerone)){
	    array_push($playertwo,$row);
	    }

	    }

	    foreach ($tmp as $row) {
	    $trumpsuit = array_slice($tmp, -1);
		    if(!in_array($row,$trumpsuit)){
		    array_push($deck,$row);
		    }
	    }

	    $result = array();
	    array_push($result, $deck, $playerone, $playertwo, $trumpsuit);

	   	echo json_encode($result);
	      // var_dump($result[3]);
	      // exit();
	}

}
?>